﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SensitivityTest.model;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace SensitivityTest
{
    public partial class MDIParent1 : Form
    {
        public static string localIP;
        public static string ClientSoftwareAddress;
        public static string ScodeAndUpload;
        private int childFormNumber = 0;
        private Boolean keyPass = false;
        public MDIParent1()
        {
            InitializeComponent();
        }

        //private void ShowNewForm(object sender, EventArgs e)
        //{
        //    Form childForm = new Form();
        //    childForm.MdiParent = this;
        //    childForm.Text = "窗口 " + childFormNumber++;
        //    childForm.Show();
        //}

        private void oIP3测试ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            oIP3测试ToolStripMenuItem.Enabled = false;
            Frm_Main f1 = new Frm_Main(this);
            f1.MdiParent = this;
            f1.Show();
           
            //if (f1.ShowDialog() == DialogResult.OK) 
            //{
            //    oIP3测试ToolStripMenuItem.Enabled = true;
            //}
        }

        public void SetoIP3测试ToolStripMenuItemEnable()
        { 
            oIP3测试ToolStripMenuItem.Enabled=true;
        }

        private void 添加配置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            添加配置ToolStripMenuItem.Enabled = false;
            Frm_Config_Add addConfig = new Frm_Config_Add(this);
            addConfig.MdiParent = this;
            addConfig.Show();
            //if (addConfig.ShowDialog() == DialogResult.OK)
            //{
            //    添加配置ToolStripMenuItem.Enabled = true;
            //}
        }

        private void 修改配置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            修改配置ToolStripMenuItem.Enabled = false;
            groupBox1.Show();
            textBox1.Text = "";
            textBox1.Focus();
        }

        private void MDIParent1_Load(object sender, EventArgs e)
        {
            groupBox1.Hide();
            GetLocalIP();                                                   //获取服务器地址
            if (!System.IO.Directory.Exists("d:/OIP3校准数据"))
            {
                System.IO.Directory.CreateDirectory("d:/OIP3校准数据");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "mobioip3")
            {
                keyPass = true;
                Frm_Config_update updateConfig = new Frm_Config_update();
                //updateConfig.MdiParent = this;
                //updateConfig.Show();
                if (updateConfig.ShowDialog()==DialogResult.OK)
                {
                    修改配置ToolStripMenuItem.Enabled = true;
                }
                groupBox1.Hide();
            }
            else
            {
                keyPass = false;
                MessageBox.Show(" 密码错误");
                修改配置ToolStripMenuItem.Enabled = true;
                groupBox1.Hide();
            }
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter || e.KeyData==Keys.Space)
            {
                button1.Focus();
            }
        }

        public void a()
        {
            oIP3测试ToolStripMenuItem.Enabled = true;
        }

        private void fSL命令测试ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            testCommand tc = new testCommand();
            tc.MdiParent = this;
            tc.Show();
        }
        private void GetLocalIP()
        {
            string HostName = Dns.GetHostName();//获取本机名称
            IPAddress[] ipadrlist = Dns.GetHostAddresses(HostName);//获取本机IP
            foreach (IPAddress ipa in ipadrlist)
            {
                if (ipa.AddressFamily == AddressFamily.InterNetwork)
                    localIP = ipa.ToString();
            }
            string NetSeg = localIP.Split('.')[2];
            if (int.Parse(NetSeg) >= 80 && int.Parse(NetSeg) <= 89)
            {
                SQLData.mServer = "10.53.80.11";
                toolStripStatusLabel.Text = "服务器：吉安";
                ClientSoftwareAddress = "http://10.53.80.11/pa/WebService/ServiceForCommon/ClientSoftware_VersionControl_Service.asmx";
                ScodeAndUpload = "http://10.53.80.11/pa/WebService/ServiceForClient/Test_Record_OIP3_DataUploadAndProcessControl_Service.asmx";
            }
            else if (int.Parse(NetSeg) >= 60 && int.Parse(NetSeg) <= 69)
            {
                SQLData.mServer = "10.53.60.6";
                ClientSoftwareAddress = "http://10.53.60.6/pa/WebService/ServiceForCommon/ClientSoftware_VersionControl_Service.asmx";
                ScodeAndUpload = "http://10.53.60.6/pa/WebService/ServiceForClient/Test_Record_OIP3_DataUploadAndProcessControl_Service.asmx";
                toolStripStatusLabel.Text = "服务器：西安";
            }
            else
            {
                SQLData.mServer = "10.53.20.170";
                ClientSoftwareAddress="http://10.53.20.170/pa/WebService/ServiceForCommon/ClientSoftware_VersionControl_Service.asmx";
                ScodeAndUpload = "http://10.53.20.170/pa/WebService/ServiceForClient/Test_Record_OIP3_DataUploadAndProcessControl_Service.asmx";
                toolStripStatusLabel.Text = "服务器：深圳";
            }
        }

    }
}
